﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class ReplaceEye : MonoBehaviour
{
    public Camera camera;
    private Texture2D lframe;
    private Texture2D rframe;
 
    void Start()
    {
        lframe = null;
        rframe = null;
    }

    void Update()
    {
    }

    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!camera) {
            camera = GetComponent<Camera>();
        }
            
        if (lframe || rframe) {
            if (camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Left && lframe) {
                Graphics.Blit(lframe, destination);
            }
            if(camera.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right && rframe){
                Graphics.Blit(rframe, destination);
            }
        }
        else {
            Graphics.Blit(source, destination);
        }
    }

    public void setLframe(Texture2D frame)
    {
        this.lframe = frame;
    }

    public void setRframe(Texture2D frame)
    {
        this.rframe = frame;
    }
}
